package com.shuai.mapper;



import com.shuai.annotation.AutoFill;
import com.shuai.entity.Enterprise;

import com.shuai.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EnterpriseMapper {

    /**
     * 根据用户名查询企业
     * @param enterpriseName
     * @return
     */
    @Select("select * from enterprise where enterprise_name = #{enterpriseName}")
    Enterprise getByEnterpriseName(String enterpriseName);

    /**
     * 插入企业数据
     * @param enterprise
     */


    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into  enterprise( enterprise_name, password, description , logo,create_time, update_time,postal_code,address,phoneor_fax,email,contact,complaint_phone )" +
            "value " +
            "(#{enterpriseName}, #{password},#{description},#{logo} ,#{createTime},#{updateTime},#{postalCode} ,#{address},#{phoneorFax},#{email},#{contact},#{complaintPhone})")
    void insert(Enterprise enterprise);


    /**
     *更改企业信息
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Enterprise enterprise);

    /**
     *根据Id查询企业信息
     */
    @Select("select * from enterprise where id = #{id}")
    Enterprise getById(Long id);


    /**
     * 根据id检查密码
     * @param enterpriseId
     * @param password
     * @return
     */
    @Select("select count(*) from enterprise where id = #{enterpriseId} and password = #{password}")
    int checkPassword(Long enterpriseId, String password);

    /**
     *
     * @param enterpriseId
     * @param password
     */
    @Update("update enterprise set password = #{password} where id = #{enterpriseId}")
    void updatePassword(Long enterpriseId, String password);

}
